"use strict";

// const path = require("path");
// const { getUserHomeAppDir } = require("ee-core/ps");
// const { logger } = require('ee-core/log');
//electron-store 6.0.1 以后不再支持CommonJS require导入，以后是ES模块，需改为import导入
const Store = require("electron-store");


/**
 * json数据存储
 * @class
 */
class JsondbService {

  constructor() {

    this.store = new Store({
      name: "settings"
    });
  }

  async getPath() {
    return this.store.path;
  }
 
  async getConf() {
    return JSON.stringify(this.store.store);
  } 
  async get(key) {    
    let val = this.store.get(key);
    console.log(key, val);
    return val;
  }

  async clear() {    
    this.store.clear();
  }

  async set(info) {    
    this.store.set(info);
    return "JsondbService set ok";
  }

  async delete(key) {
    let ret = this.store.delete(key);
    console.log("JsondbService del:", key, ret);
    return "JsondbService delete ok";;
  }

  async get(key) {    
    let val = this.store.get(key);
    console.log("JsondbService get:", key, val);
    return val;
  }

  async getMetaData() {
    return JSON.stringify(this.store.store);
  }

}

JsondbService.toString = () => "[class JsondbService]";
module.exports = {
  JsondbService,
  jsondbService: new JsondbService()
};

